﻿using Autofac;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wittur.GenereateKongCoCPDF.Core.Services;
using Alexinea.Autofac.Extensions.DependencyInjection;

namespace Wittur.GenereateKongCoCPDF.Core.Extensions
{
    public static class ServicesExtensions
    {
        /// <summary>
        ///  autofac的容器注入和配置文件注入
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static ContainerBuilder ConfigureSelf(this ContainerBuilder builder)
        {
            // autofac实现的配置文件注入
            var services = new ServiceCollection();
            // register appsettings.json
            //services.Configure<User>("UserConfig", Settings.Instance.Configuration.GetSection("User"));
            builder.Populate(services);
            // register services repositories
            builder.RegisterAssemblyTypes(typeof(UserRepository).Assembly)
                   .Where(t => t.Name.EndsWith("Repository"))
                   .AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(typeof(UserService).Assembly)
                   .Where(t => t.Name.EndsWith("Service"))
                   .AsImplementedInterfaces();

            return builder;
        }
    }
}
